﻿using CustomPlayerEffects;
using MapGeneration;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;
using RoleCustom.Main;
using System.Linq;
using UnityEngine;
using Utils;


namespace RoleCustom.Event
{
    /// <summary>
    /// 
    /// </summary>
    public class SCP173Event
    {
        [PluginEvent(ServerEventType.PlayerSpawn)]
        public void OnPlayerSpawn(PlayerSpawnEvent ev)
        {
            if (ev.Player.Role != PlayerRoles.RoleTypeId.Scp173) return;

            TimeCoroutine.Delay(0.3f, () =>
            {
                PlayerUtils.SetHP(ev.Player,
                    CodeLoad.Singleton.Config.SCP173Event.Health,
                    CodeLoad.Singleton.Config.SCP173Event.Health);

                PlayerUtils.SetAP(ev.Player,
                    CodeLoad.Singleton.Config.SCP173Event.AHealth,
                    CodeLoad.Singleton.Config.SCP173Event.AHealth);

                if (Round.IsLocked) return;

                this.SetSpawnPoint(ev);
            });
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="ev"></param>
        private void SetSpawnPoint(PlayerSpawnEvent ev)
        {
            RoomIdentifier match = Map.Rooms.ToList().First(room => room.Name == RoomName.Lcz173);

            if (match == null)
            {
                Log.Info("SCP173Event|查询房间失败");
                return;
            }

            GameObject point = new GameObject();
            point.transform.parent = match.ApiRoom.GameObject.transform;
            point.transform.localPosition = new Vector3(16.5f, 13f, 8f);

            ev.Player.Position = point.transform.position;
        }
    }
}
